<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/tools/cpptools/SingleFactory.h 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_1563a38af0d3a5e4a6330d6d45e9792a.html">tools</a></li><li class="navelem"><a class="el" href="dir_03ac758817843737b5fab9a7952176a3.html">cpptools</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">SingleFactory.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_single_factory_8h.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef __SINGLEFACTORY_H__</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define __SINGLEFACTORY_H__</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160; </div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;../../thread/Mutex.h&quot;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &quot;../../thread/SharedPtr.h&quot;</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160; </div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160; </div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;</div>
<div class="line"><a name="l00013"></a><span class="lineno"><a class="line" href="class_c_single_factor.html">   13</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_c_single_factor.html">CSingleFactor</a></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;{</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00016"></a><span class="lineno"><a class="line" href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">   16</a></span>&#160;    <span class="keyword">static</span> <a class="code" href="class_shared_ptr.html">SharedPtr&lt;T&gt;</a> <a class="code" href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">g_singlePtr</a>;</div>
<div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="class_c_single_factor.html#a3dca33cfa7dd14c8031fc52f99c51a6e">   17</a></span>&#160;    <span class="keyword">static</span> <a class="code" href="class_c_mutex.html">CMutex</a> <a class="code" href="class_c_single_factor.html#a3dca33cfa7dd14c8031fc52f99c51a6e">g_mutexPtr</a>;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="class_c_single_factor.html#ae07259bae0cbb58e32f263b27ac027c8">   20</a></span>&#160;    <span class="keyword">static</span> T* <a class="code" href="class_c_single_factor.html#ae07259bae0cbb58e32f263b27ac027c8">GetInstance</a>()</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;    {</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">g_singlePtr</a>.<a class="code" href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">Get</a>() == <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>)</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        {</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;            <a class="code" href="class_c_lock_gurad.html">CLockGurad</a> lk(&amp;<a class="code" href="class_c_single_factor.html#a3dca33cfa7dd14c8031fc52f99c51a6e">g_mutexPtr</a>);</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;            <span class="keywordflow">if</span> (<a class="code" href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">g_singlePtr</a>.<a class="code" href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">Get</a>() == <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>) {</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;                <a class="code" href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">g_singlePtr</a>.<a class="code" href="class_shared_ptr.html#a0b0a4c8396bf40f91994f729855c0a5a">Reset</a>(<span class="keyword">new</span> T());</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;            }</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;        }</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">g_singlePtr</a>.<a class="code" href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">Get</a>();</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    }</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;};</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<a class="code" href="class_shared_ptr.html">SharedPtr&lt;T&gt;</a> <a class="code" href="class_c_single_factor.html">CSingleFactor&lt;T&gt;::g_singlePtr</a>;</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<a class="code" href="class_c_mutex.html">CMutex</a> <a class="code" href="class_c_single_factor.html">CSingleFactor&lt;T&gt;::g_mutexPtr</a>;</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160; </div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160; </div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="preprocessor">#endif // __SINGLEFACTORY_H__</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclass_c_mutex_html"><div class="ttname"><a href="class_c_mutex.html">CMutex</a></div><div class="ttdoc">常规锁</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00025">Mutex.h:25</a></div></div>
<div class="ttc" id="aclass_shared_ptr_html"><div class="ttname"><a href="class_shared_ptr.html">SharedPtr&lt; T &gt;</a></div></div>
<div class="ttc" id="aclass_c_single_factor_html_ae07259bae0cbb58e32f263b27ac027c8"><div class="ttname"><a href="class_c_single_factor.html#ae07259bae0cbb58e32f263b27ac027c8">CSingleFactor::GetInstance</a></div><div class="ttdeci">static T * GetInstance()</div><div class="ttdoc">生成一个单列模式实例</div><div class="ttdef"><b>Definition:</b> <a href="_single_factory_8h_source.html#l00020">SingleFactory.h:20</a></div></div>
<div class="ttc" id="aclass_shared_ptr_html_a0f15d2d3d2834b0667791f3abfd9e0d7"><div class="ttname"><a href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">SharedPtr::Get</a></div><div class="ttdeci">Ty * Get()</div><div class="ttdef"><b>Definition:</b> <a href="_shared_ptr_8h_source.html#l00202">SharedPtr.h:202</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="aclass_c_lock_gurad_html"><div class="ttname"><a href="class_c_lock_gurad.html">CLockGurad</a></div><div class="ttdoc">常规锁包装器</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00041">Mutex.h:41</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="aclass_c_single_factor_html_a3dca33cfa7dd14c8031fc52f99c51a6e"><div class="ttname"><a href="class_c_single_factor.html#a3dca33cfa7dd14c8031fc52f99c51a6e">CSingleFactor::g_mutexPtr</a></div><div class="ttdeci">static CMutex g_mutexPtr</div><div class="ttdef"><b>Definition:</b> <a href="_single_factory_8h_source.html#l00017">SingleFactory.h:17</a></div></div>
<div class="ttc" id="aclass_shared_ptr_html_a0b0a4c8396bf40f91994f729855c0a5a"><div class="ttname"><a href="class_shared_ptr.html#a0b0a4c8396bf40f91994f729855c0a5a">SharedPtr::Reset</a></div><div class="ttdeci">void Reset(Ty *p)</div><div class="ttdef"><b>Definition:</b> <a href="_shared_ptr_8h_source.html#l00175">SharedPtr.h:175</a></div></div>
<div class="ttc" id="atools_8h_html_ab689500aaec0db066e3ac9483d3fe425"><div class="ttname"><a href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a></div><div class="ttdeci">#define NullPtr</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00119">tools.h:119</a></div></div>
<div class="ttc" id="aclass_c_single_factor_html_aea2062281f4f7a23b7a2631f00bcaa5d"><div class="ttname"><a href="class_c_single_factor.html#aea2062281f4f7a23b7a2631f00bcaa5d">CSingleFactor::g_singlePtr</a></div><div class="ttdeci">static SharedPtr&lt; T &gt; g_singlePtr</div><div class="ttdef"><b>Definition:</b> <a href="_single_factory_8h_source.html#l00016">SingleFactory.h:16</a></div></div>
<div class="ttc" id="aclass_c_single_factor_html"><div class="ttname"><a href="class_c_single_factor.html">CSingleFactor</a></div><div class="ttdoc">单例模式工具类</div><div class="ttdef"><b>Definition:</b> <a href="_single_factory_8h_source.html#l00013">SingleFactory.h:13</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
